﻿'    This file is part of The Global Distribution System.

'    The Global Distribution System is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 3 of the License, or
'    (at your option) any later version.

'    The Global Distribution System is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with The Global Distribution System.  If not, see <http://www.gnu.org/licenses/>.

Public Class PokemonInfo
    Private Property PkmID As String = String.Empty
    Private OldData As DLL.Information

    Public Sub New(ByVal data As DLL.Information)
        InitializeComponent()

        tb_pkm_name.Text = data.Name
        tb_gender.Text = data.Gender
        tb_origin.Text = data.Origin

        tb_otname.Text = data.OTName
        tb_OTID.Text = data.OTID.ToString
        tb_otsid.Text = data.SID.ToString
        tb_nickname.Text = If(data.NickName = String.Empty, "No Nickname", data.NickName)

        PD_Number.Value = data.DexNumber

        With data.PkmEV
            EV_atk.Value = CDec(.Attack)
            EV_def.Value = CDec(.Defense)
            EV_HP.Value = CDec(.HP)
            EV_SA.Value = CDec(.Sp_Atk)
            EV_SD.Value = CDec(.Sp_Def)
            EV_Speed.Value = CDec(.Speed)
        End With

        With data.PkmIV
            IV_atk.Value = CDec(.Attack)
            IV_def.Value = CDec(.Defense)
            IV_HP.Value = CDec(.HP)
            IV_SA.Value = CDec(.Sp_Atk)
            IV_SD.Value = CDec(.Sp_Def)
            IV_Speed.Value = CDec(.Speed)
        End With

        With data.PkmStats
            CS_atk.Value = CDec(.Attack)
            CS_def.Value = CDec(.Defense)
            CS_HP.Value = CDec(.HP)
            CS_SA.Value = CDec(.Sp_Atk)
            CS_SD.Value = CDec(.Sp_Def)
            CS_Speed.Value = CDec(.Speed)
        End With

        tb_move1.Text = String.Format("1: {0}", data.Moves(0))
        tb_move2.Text = String.Format("2: {0}", data.Moves(1))
        tb_move3.Text = String.Format("3: {0}", data.Moves(2))
        tb_move4.Text = String.Format("4: {0}", data.Moves(3))

        lbl_level.Text = String.Format("Level: {0}", data.Level.ToString)

        AllowChange = True
        cb_fateful.Checked = data.FateFulEncounter
        cb_shiny.Checked = data.Shiny
        AllowChange = False

        Me.Text = If(data.NickName = String.Empty, String.Format("Information on: {0}", data.Name), String.Format("Information on {0} ({1})", data.NickName, data.Name))
        Me.PkmID = data.InternalID
        OldData = data

    End Sub

    Public Property MainFormParent As MainForm

    Private Sub btn_confirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_confirm.Click
        MainFormParent.BC.SendMessage(New DLL.ReservePokemon With {.ID = Me.PkmID, .Overwrite = MainFormParent.cb_override.Checked})
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_cancel.Click
        Me.Close()
    End Sub

    Private Property AllowChange As Boolean = False
    Private Sub cb_fateful_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb_fateful.CheckedChanged
        If Not AllowChange Then cb_fateful.Checked = OldData.FateFulEncounter
    End Sub

    Private Sub cb_shiny_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb_shiny.CheckedChanged
        If Not AllowChange Then cb_shiny.Checked = OldData.Shiny
    End Sub

    Private Sub btn_report_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_report.Click
        Select Case MessageBox.Show("Do you want to report this Pokémon?",
                                    "Report this Pokémon",
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question)
            Case Windows.Forms.DialogResult.Yes
                MainFormParent.BC.SendMessage(New DLL.ReportPokemon With {.ID = OldData.InternalID})
                MessageBox.Show("This Pokémon has been reported. Thank you for helping keep the system clean!", "Report filed.", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Me.Close()

        End Select
    End Sub

    Private Sub btn_download_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_download.Click
        MainFormParent.BC.SendMessage(New DLL.RequestPokemonInformation With {.ID = OldData.InternalID, .KeyOption = DLL.Options.Download})
    End Sub

End Class